﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yto.Common;

namespace Yto.Entities
{
    public static class EntityCommon
    {
        public static Type GetGeneticPrimaryKey(Type entityType)
        {
            foreach( var interfaceType in entityType.GetInterfaces())
            {
                if(interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IEntity<>))
                {
                    return interfaceType.GenericTypeArguments[0];
                }
            }
            throw new BaseException($"{nameof(entityType)} is not invalid!");
        }
    }
}
